home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / t100.zoo / vt100.c < prev   
C/C++ Source or Header  |  1991-09-21  |  19KB  |  983 lines

  1. #define DEBUG
  2.  
  3. /*
  4.  *    vt100.c - emulates a vt100 using vt52 codes when possible
  5.  *
  6.  *    this code handles an escape sequence only. on entry, the ESC has
  7.  *    already been read from AUX:. it writes all output to CON: via bios.
  8.  *
  9.  *    this compiles (and runs :-) with gcc 1.40 and mint libraries, PL 10.
  10.  *    it should also work with "normal" gcc libraries.
  11.  */
  12.  
  13.  
  14. #ifndef lint
  15. static char *rcsid_vt100_c = "$Id: vt100.c,v 1.0 1991/09/12 20:32:56 rosenkra Exp $";
  16. #endif
  17.  
  18. /*
  19.  * $Log: vt100.c,v $
  20.  * Revision 1.0  1991/09/12  20:32:56  rosenkra
  21.  * Initial revision
  22.  *
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <osbind.h>
  28. #include "t100.h"
  29.  
  30.  
  31.  
  32. /*
  33.  *    macro to get a char from AUX. we check status some number of times.
  34.  *    if no char available, we may have a hosed connection or host screwed
  35.  *    up. otherwise, if char available, get it. use BIOS...
  36.  */
  37. #define GET_NEXT_CHAR \
  38. { \
  39.     long counter; \
  40.     for (counter = 1000; counter; counter--) {\
  41.     if (Bconstat (AUX)) break; \
  42.     } \
  43.     if (counter == 0) goto no_char_avail; \
  44.     c = (int) Bconin (AUX); \
  45. }
  46.  
  47.  
  48. /*
  49.  *    default value if none specified. if not 0, be careful!
  50.  */
  51. #define VAL_DEFAULT    0
  52.  
  53.  
  54. /*
  55.  *    modes, etc...
  56.  */
  57. extern int    bold;            /* OFF 1m */
  58. extern int    underline;        /* OFF 4m */
  59. extern int    blinking;        /* OFF 5m */
  60. extern int    reverse;        /* OFF 7m */
  61. extern int    wrap;            /* ON (set) */
  62. extern int    video;            /* 0=normal (reset) */
  63. extern int    repeat;            /* ON (set) */
  64. extern int    curskey;        /* OFF (reset) */
  65. extern int    keypad;            /* 0=normal (reset) */
  66. extern int    colwidth;        /* 0=80 (reset), 1=132 */
  67. extern int    smooth;            /* OFF (reset) */
  68. extern int    origmode;        /* 0=normal (reset) */
  69.  
  70.  
  71.  
  72. /*------------------------------*/
  73. /*    vt100            */
  74. /*------------------------------*/
  75. void vt100 ()
  76. {
  77.  
  78. /*
  79.  *    emulate vt100. upon entry, we got a ESC char from AUX. only the
  80.  *    ESC was read so far.
  81.  *
  82.  *    note: in order to report things back to the host, we must know
  83.  *    things like baud rate, parity, etc. these are not in the termcap,
  84.  *    however, so don't sweat it for now. we also can't report postion.
  85.  *
  86.  *    we do not do character generators (g0 and g1).
  87.  *
  88.  *    we do not do LEDs.
  89.  *
  90.  *    here is the basic logic:
  91.  *
  92.  *        we got an ESC already from AUX.
  93.  *
  94.  *        get_next_char.
  95.  *        if (current_char == >,=,8,7,or M)
  96.  *            handle.
  97.  *            done.
  98.  *        else if (current_char == [)
  99.  *            get_next_char.
  100.  *            if (current_char == ?)
  101.  *                get_next_char. it should be 1-8. save val.
  102.  *                get_next_char. it should be h or l.
  103.  *                handle.
  104.  *                done.
  105.  *            else if (current_char == number)
  106.  *                read all of number. convert and save.
  107.  *                get_next_char.
  108.  *            else
  109.  *                val1 = 0 (or 1)
  110.  *            if (current_char == ;)
  111.  *                get_next_char.
  112.  *                if (current_char == number)
  113.  *                    read all of number. convert and save.
  114.  *                    get_next_char.
  115.  *                else
  116.  *                    val2 = 0 (or 1)
  117.  *                switch (current_char)
  118.  *                  H or f
  119.  *                  r
  120.  *                  R
  121.  *            else
  122.  *                switch (current_char)
  123.  *                  A
  124.  *                  B
  125.  *                  C
  126.  *                  D
  127.  *              H
  128.  *                  J
  129.  *                  K
  130.  *                  L
  131.  *                  M
  132.  *                  P
  133.  *                  g
  134.  *                  h
  135.  *                  l
  136.  *                  m
  137.  *                  n
  138.  *                  x
  139.  *                  @
  140.  *        else
  141.  *            error?
  142.  *
  143.  */
  144.  
  145. /*
  146.  
  147. here are likely codes to be seen. xxx is optional, 0, 1, or 2 chars:
  148.  
  149. \E    [    xxx    J
  150. \E    [    xxx    K
  151. \E    [    xxx    ;    xxx    H    position cursor
  152. \E    [    xxx    H            special case of position cursor
  153. \E    [    xxx    ;    xxx    r
  154. \E    [    xxx    C            cursor right
  155. \E    [    xxx    D            cursor left
  156. \E    [    xxx    B            cursor down
  157. \E    [    xxx    A            cursor up
  158. \E    8
  159. \E    7
  160. \E    M
  161. \E    [    ?    1    l        cursor key mode reset
  162. \E    [    ?    1    h                set
  163. \E    [    ?    3    l        col width reset (to 80)
  164. \E    [    ?    4    l
  165. \E    [    ?    5    l
  166. \E    [    ?    7    h
  167. \E    [    ?    8    h        auto repeat mode set
  168. \E    >
  169. \E    =
  170. \E    [    1    m
  171. \E    [    4    m
  172. \E    [    5    m
  173. \E    [    7    m
  174. \E    [    0    m
  175. \E    [    m
  176.  
  177.  
  178. this is a real vt100 termcap with equiv vt52 codes:
  179.  
  180. vt100            vt52        desc
  181.  
  182. :cd=\E[J:        :\EJ:        clear display after cursor
  183. :ce=\E[K:        :\EK:        clear to end of line
  184. :cl=\E[;H\E[2J:        :\EH\EJ:    home cursor, clear screen
  185. :cm=\E[%i%d;%dH:    :\EY%+ %+ :    move to row #1 and col #2
  186. :cs=\E[%i%d;%dr:    ---        change scrolling region to rows #1 to #2
  187. :ho=\E[H:        :\EH:        move cursor home
  188. :is=\E[1;24r\E[24;1H:    :\Ev\Ee:    initialization string (wrapon, curs vis)
  189. :nd=\E[C:        :\EC:        non-destructive space (move right)
  190. :rc=\E8:        :\Ek:        restore cursor to position saved by sc
  191. :sc=\E7:        :\Ej:        save absolute cursor position
  192. :sr=\EM:        :\EI:        scroll reverse one line
  193. :up=\E[A:        :\EA:        move cursor up
  194.  
  195. :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:    reset to sane modes
  196.  
  197. :ke=\E[?1l\E>:        ---        turn keypad off, if possible
  198. :ks=\E[?1h\E=:        ---        turn keypad on, if possible
  199.  
  200. :mb=\E[5m:        ---        turn on blinking attribute
  201. :md=\E[1m:        ---        turn on bold
  202. :me=\E[m:        :\Eq:        turn off all attributes
  203. :mr=\E[7m:        :\Ep:        turn on reverse video
  204.  
  205. :se=\E[m:        :\Eq:        end standout (reverse) mode
  206. :so=\E[7m:        :\Ep:        begin standout (reverse) mode
  207. :ue=\E[m:        ---        end underline mode
  208. :us=\E[4m:        ---        begin underline mode
  209.  
  210.  */
  211.  
  212.  
  213.     register int    c;
  214.     register int    val1;
  215.     register int    val2;
  216.     int        row;
  217.     int        col;
  218.     int        i;
  219.  
  220.  
  221.  
  222.  
  223.     /*
  224.      *   this is first char after an ESC.
  225.      */
  226.     GET_NEXT_CHAR;
  227.  
  228.  
  229.     /*
  230.      *   what is it?
  231.      */
  232.     switch (c)
  233.     {
  234.     case 'Z':            /* terminal ID */
  235.         /* this is obsolete. use ESC [ c */
  236.         return;
  237.         break;    /*NOTREACHED*/
  238.  
  239.     case 'c':            /* reset to initial state */
  240.         vt100_reset ();
  241.         return;
  242.         break;    /*NOTREACHED*/
  243.  
  244.     case 'H':            /* set tab at current position */
  245.         return;
  246.         break;    /*NOTREACHED*/
  247.  
  248.     case 'D':            /* index */
  249.         Bconout (CON, (int) 27);
  250.         Bconout (CON, (int) 'B');
  251.         return;
  252.         break;    /*NOTREACHED*/
  253.  
  254.     case 'M':            /* scroll reverse one line */
  255.         Bconout (CON, (int) 27);
  256.         Bconout (CON, (int) 'I');
  257.         return;
  258.         break;    /*NOTREACHED*/
  259.  
  260.     case 'E':            /* next line */
  261.         Bconout (CON, (int) 13);
  262.         Bconout (CON, (int) 27);
  263.         Bconout (CON, (int) 'B');
  264.         return;
  265.         break;    /*NOTREACHED*/
  266.  
  267.     case '>':            /* reset keypad (normal) */
  268.         keypad = 0;
  269.         return;
  270.         break;    /*NOTREACHED*/
  271.  
  272.     case '=':            /* set keypad (application) */
  273.         keypad = 1;
  274.         return;
  275.         break;    /*NOTREACHED*/
  276.  
  277.     case '8':            /* restore cursor to saved loc */
  278.         Bconout (CON, (int) 27);
  279.         Bconout (CON, (int) 'k');
  280.         return;
  281.         break;    /*NOTREACHED*/
  282.  
  283.     case '7':            /* save cursor location */
  284.         Bconout (CON, (int) 27);
  285.         Bconout (CON, (int) 'j');
  286.         return;
  287.         break;    /*NOTREACHED*/
  288.  
  289.     case '[':
  290.         /*
  291.          *   get next one...
  292.          */
  293.         GET_NEXT_CHAR;
  294.  
  295.         if (c == '?')
  296.         {
  297.             /*
  298.              *   next char SHOULD be a number...
  299.              */
  300.             GET_NEXT_CHAR;
  301.  
  302.             if ((c >= '0') && (c <= '9'))
  303.             {
  304.                 /*
  305.                  *   get all of number. store as int val1.
  306.                  */
  307.                 val1 = 0;
  308.                 do
  309.                 {
  310.                     val1 = (10 * val1) + (c - '0');
  311.  
  312.                     GET_NEXT_CHAR;
  313.     
  314.                 } while ((c >= '0') && (c <= '9'));
  315.  
  316.  
  317.                 /*
  318.                  *   what was last char? (one causing do/while
  319.                  *   to stop)
  320.                  */
  321.                 if (c == 'l')
  322.                 {
  323.                     switch (val1)
  324.                     {
  325.                     case 1:        /* reset cursor key */
  326.                         curskey = 0;
  327.                         return;
  328.                         break;    /*NOTREACHED*/
  329.  
  330.                     case 2:        /* change mode */
  331.                         /*
  332.                          *   this may not be portable
  333.                          */
  334.                         return;
  335.                         break;    /*NOTREACHED*/
  336.  
  337.                     case 3:        /* reset col width */
  338.                         colwidth = 0;
  339.                         return;
  340.                         break;    /*NOTREACHED*/
  341.  
  342.                     case 4:        /* reset smooth scroll*/
  343.                         smooth = 0;
  344.                         return;
  345.                         break;    /*NOTREACHED*/
  346.  
  347.                     case 5:        /* reset screen mode */
  348.                         /*
  349.                          *   normal video. bg is color
  350.                          *   0. fg depends on rez.
  351.                          *   black is low intens (0),
  352.                          *   white is high (777).
  353.                          */
  354.                         switch (Getrez ())
  355.                         {
  356.                         case 0:
  357.                             Setcolor (0,  0x777);
  358.                             Setcolor (15, 0);
  359.                             break;
  360.                         case 1:
  361.                             Setcolor (0, 0x777);
  362.                             Setcolor (3, 0);
  363.                             break;
  364.                         case 2:
  365.                             Setcolor (0, 0x777);
  366.                             Setcolor (1, 0);
  367.                             break;
  368.                         }
  369.                         video = 0;
  370.                         return;    /*NOTREACHED*/
  371.                         break;
  372.  
  373.